<%
	[res].user = getRes(getUser!);
	.params=message.params:-'find'; //action, resource, predicate, object
	.find=getp('find');
	.p=params['p']!=() ? 'o' : 'p';
	.onclick=p=='o'?'return returnToParent(this);':"return stayInSelector(this);";
	.filteredList=?
	(	.l=$:!
		( .ps=params+{:p=>[res]$->getId()};
			checkAction{ps,user} ?
			{	actref{ps,$->getTitle(),(),onclick}, ', '
			}
		);
		l ? (l[-1]>>=1;);
		l
	);
	.action = uncaps(params['action']);
	[stateable].res=getRes(params['resource']);
	`meta.`@action ? (res=res->getMeta(); );
	.resName = res->getTitle();
	.htmlSel = '<b style="background-color:#D8E8FF;">Select...</b>';
	.sentence = {resName,' ',p=='p'?htmlSel:getRes(params['p'])->getTitle(), ' ',p=='p'?'...':(`meta$`@action?{'"',htmlSel,'"'}:htmlSel)};
	'inv'@action ? (sentence=-sentence);
%>
<%=pageHead%> 
<link href="genlayout.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="script.js"></script>
<title>Select resource</title>
</head>
<body>
<p><%=sentence%></p>
<%=blockHead%>
Select a resource
<%=blockEnd%>
<div class="resource"><div class="border"><div class="resourceBox"><div style="height:260px;">
<ul style="line-height: 150%;">
<li>
<form action="selector.tsp" style="display:inline;">
<%=params%!{'<input type="hidden" name="',$.key,'" value="',tyleToUrl($.data),'" />'}%>
<input type="submit" value="Find" />
<input type="text" name="find"/>
</form>
</li><%
	find!=()?(
		.list = filteredList(Search.queryName{find,user});
		list ? (%>
<li>Found: <%=list%>
</li><%
		);
	) :
	(
		p=='o' && !('inv'@action) && params['p'] == hasAccessibilityResource.id ?
		(	%>
	<li>Defaults: <%=filteredList(AccessResource->getSubClasses(1):!isTrue{user,CanEditIfResource,$}?$ )%>
	</li><%
		):
		(
			.list = filteredList(getv("history"));
			list ? (%>
<li>Recent: <%=list%>
</li><%
			);
		);
		.ps=params+{:p=>-1};
		p=='o' ? checkAction{ps,user} (%>
<li><%=actref{ps,'Latest search results',(),onclick}%>
</li><%
	);
);%>
</ul>
</div><%=blockEnd%>
<div style="width:80px;margin: 10px auto 0px auto;">
<a href="resourcerer.tsp?resource=<%=tyleToUrl(resName)%>" onclick="return returnToParent(this);" class="action">Cancel</a>
</div>
</body>
</html>